package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.WeChatUser;
import com.ala4.oxcafe.repository.WeChatUserRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author PING
 * @date 2025/8/16 13:06
 */
@Slf4j
@RestController
@RequestMapping("/wechat-user")
@AllArgsConstructor
@Tag(name = "微信用户管理", description = "用于管理微信用户")
public class WeChatUserController {

    private final WeChatUserRepository weChatUserRepository;

    @Operation(summary = "分页查询微信用户")
    @GetMapping("/page")
    public R<PageResult<WeChatUser>> page(PageDomain pageDomain, WeChatUser weChatUser) {
        return R.ok(PageResult.iPage(weChatUserRepository.weChatUserPage(pageDomain, weChatUser)));
    }

    @Operation(summary = "使用code获取微信手机号-和当前用户绑定")
    @GetMapping("/bind-phone/{phoneCode}")
    public R<WeChatUser> phone(@PathVariable String phoneCode) {
        return R.ok(weChatUserRepository.bindUserPhone(phoneCode));
    }

}
